﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class DataBase_Controles_menu : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["cohortAtiva"] != null && !string.IsNullOrEmpty(Request.QueryString["redirectUrl"]))
                Response.Redirect(Request.QueryString["redirectUrl"]);
            
            configuraBonecos();
            validaCohort();
            LinkMenu();
        }
    }
   
    private void validaCohort()
    {
        if (Session["cohortAtiva"] != null)
        {
            configuraBonecos();
            switch (Session["cohortAtiva"].ToString())
            {
                case "1":
                    btBrazil.ImageUrl = "~/teletubbes/brazil2.jpg";
                    break;
                case "3":
                    btGuatemala.ImageUrl = "~/teletubbes/guatemala2.jpg";
                    break;
                case "4":
                    btIndia.ImageUrl = "~/teletubbes/india2.jpg";
                    break;
                case "5":
                    btPhilippines.ImageUrl = "~/teletubbes/philippines2.jpg";
                    break;
                case "2":
                    btAfrica.ImageUrl = "~/teletubbes/africa2.jpg";
                    break;
            }
        }
    }

    private void configuraBonecos()
    {
        btAfrica.ImageUrl = "~/teletubbes/africa1.jpg";
        btBrazil.ImageUrl = "~/teletubbes/brazil1.jpg";
        btGuatemala.ImageUrl = "~/teletubbes/guatemala1.1.jpg";
        btIndia.ImageUrl = "~/teletubbes/india1.jpg";
        btPhilippines.ImageUrl = "~/teletubbes/philippines1.jpg";
    }

    protected void changeCohort_Click(object sender, ImageClickEventArgs e)
    {
        ImageButton btnCohort = (ImageButton)sender;
        Session.Add("cohortAtiva", btnCohort.CommandArgument);
        Response.Redirect(Request.Url.AbsoluteUri);
    }

    protected void LinkMenu()
    {
        string strPagina;

        if (!string.IsNullOrEmpty(Request.QueryString["redirectUrl"]))
            strPagina = Request["redirectUrl"].ToString().ToLower();
        else
            strPagina = System.IO.Path.GetFileName(Request.Url.ToString().ToLower());

        switch (strPagina)
        {
            case "history.aspx":
                link_menu.ImageUrl = "~/DataBase/Img/link_menu/link_history.jpg";
                break;
            case "questionaires.aspx":
                link_menu.ImageUrl = "~/DataBase/Img/link_menu/link_questionnaires.jpg";
                break;
            case "documents.aspx":
                link_menu.ImageUrl = "~/DataBase/Img/link_menu/link_documents.jpg";
                break;
            case "publications.aspx":
                link_menu.ImageUrl = "~/DataBase/Img/link_menu/link_publications.jpg";
                break;
            case "database.aspx":
                link_menu.ImageUrl = "~/DataBase/Img/link_menu/link_database.jpg";
                break;
            case "meetings.aspx":
                link_menu.ImageUrl = "~/DataBase/Img/link_menu/link_meetings.jpg";
                break;
            case "meetings_view.aspx":
                link_menu.ImageUrl = "~/DataBase/Img/link_menu/link_meetings.jpg";
                break;
            case "links.aspx":
                link_menu.ImageUrl = "~/DataBase/Img/link_menu/link_links.jpg";
                break;
            case "news.aspx":
                link_menu.ImageUrl = "~/DataBase/Img/link_menu/link_news.jpg";
                break;
            case "news_view.aspx":
                link_menu.ImageUrl = "~/DataBase/Img/link_menu/link_news.jpg";
                break;
            case "cohortsteam.aspx":
                link_menu.ImageUrl = "~/DataBase/Img/link_menu/link_team.jpg";
                break;
        }
    }
}
